//
//  CCQPhotoAlbumViewController.swift
//  photo
//
//  Created by zhongchuren on 2018/11/20.
//  Copyright © 2018年 sundusk. All rights reserved.
//

import UIKit

class CCQPhotoAlbumViewController: UIViewController,UICollectionViewDelegate,UICollectionViewDataSource, UICollectionViewDelegateFlowLayout{
    
    let ScreenWidth  = UIScreen.main.bounds.width
    let ScreenHeight = UIScreen.main.bounds.height
    var mCollectionView:UICollectionView?

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.view.backgroundColor = UIColor.white
        
        self.setupUI()
        
        
    }
    
    
    
    func setupUI(){
        let layout = UICollectionViewFlowLayout.init()
        layout.itemSize = CGSize(width: (ScreenWidth - 20)/2, height: (ScreenWidth - 20)/2)
       
        layout.sectionInset = UIEdgeInsets(top: 5, left: 5, bottom: 5, right: 5)
        
        mCollectionView = UICollectionView.init(frame: CGRect(x:0,y:0,width:ScreenWidth,height:ScreenHeight), collectionViewLayout: layout)
        mCollectionView?.delegate = self
        mCollectionView?.dataSource = self
        mCollectionView?.register(UINib(nibName: "CCQImageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier:"cellid")
        mCollectionView?.backgroundColor = UIColor.white
       self.view.addSubview(mCollectionView!)
       

    }
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1;
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 4;
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
      
        
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellid", for: indexPath) as! CCQImageCollectionViewCell
        cell.imageButton.addTarget(self, action:#selector(addImageAction), for: UIControl.Event.touchUpInside)
     
        return cell
      
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        
    }
    
    
    @objc func addImageAction(){
        
        let secondVC = CCQBrowseImageViewController()
        
        
        
        self.navigationController?.pushViewController(secondVC, animated: true)
        
    }
    

    

   

}
